package com.situ.dayTest;

import java.nio.channels.NonWritableChannelException;
import java.rmi.server.SocketSecurityException;
import java.util.Scanner;

import org.junit.Test;
import org.junit.experimental.theories.FromDataPoints;

import com.situ.day11.Student;

public class ShuZu {
	/**
	 * 正序、倒叙
	 */
	@Test
	public void test(){
		int [] array = {1,23,34,45,65,23,23,12,2,4,54,56,};
		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i] + "\t");
		}
		System.out.println();
		//倒叙
		for (int j = array.length-1; j >= 0; j--) {
			System.out.print(array[j] + "\t");
		}
		//累加和
		int sum = 0;
		for (int k = 0; k < array.length; k++) {
			sum = sum + array[k];
		}
		System.out.println(sum);
	}
	
	
	/**
	 * 出现的个数
	 */
	
	@Test
	public void test1() {
		int count = 0;
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		for (int i = 0; i <= 9; i++) {
		for (int j = 0; j < score.length; j++) {
			if (score[j] == i) {
				count = count + 1;
			}
		}
		System.out.println(i+"出现"+count);
		count=0;
		}
	}
	
	
	@Test
	public void test2() {
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int count = 0;
		int count1 = 0;
		for (int i = 0; i < score.length; i++) {
			if (score[i] == 0) {
				count = count + 1;
			}else if (score[i] == 1) {
				count1 = count1 + 1;
			}
			
		}
		System.out.println(count);
		System.out.println(count1);
	}
	
	@Test  //switch语句打印
	public void test3() {
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int count = 0;
		int count1 = 0;
		for (int i = 0; i < score.length; i++) {
			switch (score[i]) {
			case 0:
				count++;
				break;
			case 1:
			count1++;
			break;

			default:
				System.out.println("错误");
				break;
			}
		}
		System.out.println(count);
		System.out.println(count1);
	}
	/**
	 * 奇数/偶数的个数
	 */
	@Test
	public void test4() {
		int ou = 0;
		int ji = 0;
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9,3};
		for (int i = 0; i < score.length; i++) {
			if (score[i] % 2 == 0) {
				ou = ou + 1;
			}else{
				ji = ji + 1;
			}
		}
		System.out.println("偶数的个数为： " + ou);
		System.out.println("奇数的个数为： " + ji);
	}
	
	/**
	 * 输入一组成绩，计算平均值
	 */
	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		int []array = new int[5];
		Double pingjun;
		int sum = 0;
		System.out.println("输入5个数");
		for (int i = 0; i < array.length; i++) {
			System.out.println("输入"+ (i+1) +"个数");
			array[i] = scanner.nextInt();
			sum = sum + array[i]; //输入后就加了
		}
		System.out.println(sum / array.length);
	}
	
	/**
	 * 
	 */
	
	@Test
	public void test6() {
		System.out.println("输入5个数");
		Scanner scanner = new Scanner(System.in);
		int[] array = new int[5];
		boolean huiwen = true;
		for (int i = 0; i < array.length; i++) {
			System.out.println("输入第" + (i + 1) + "个数");
			array[i]  = scanner.nextInt();
		}
		for (int j = 0; j < array.length/2; j++) { //过滤条件，如果条件不满足，结束循环
			if (array[j] != array[array.length-(j + 1)]) {
				huiwen = false;
				break;
			}
		}
		if (huiwen) {
			System.out.println("回文");
		}else {
			System.out.println("不是回文");
		}
		}
	
	/**
	 * 打印数字/字母/符号/空格的个数
	 */
	@Test
	public void test7() {
		System.out.println("输入一行字符：");
		Scanner scanner = new Scanner(System.in); 
		String cha = scanner.nextLine(); //输入的String
		char[] zifu = cha.toCharArray();  //转换为char类型
		int shuzi = 0;
		int zimu = 0;
		int kg = 0;
		int fh = 0;
		for (int i = 0; i < zifu.length; i++) {
			char ch = zifu[i];   //每个字符赋值给ch，比较
			if (ch >= '0' && ch <= '9') {
				shuzi++;
			}else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
				zimu++;
			}else if (ch == ' ') {
				kg++;
			}else {
				fh++;
			}
		}
		System.out.println("数字的个数：" + shuzi);
		System.out.println("字母的个数：" + zimu);
		System.out.println("空格的个数：" + kg);
		System.out.println("字符的个数：" + fh);
	}
	
	/**
	 * 输入3个数，由小到大输出
	 */
	@Test
	public void test8() {
		System.out.println("输入三个数字");
		Scanner scanner = new Scanner(System.in);
		System.out.println("输入第1个数:");
		int x = scanner.nextInt();
		System.out.println("输入第2个数:");
		int y = scanner.nextInt();
		System.out.println("输入第3个数:");
		int z = scanner.nextInt();
		if (x > y) {
			int temp = x;
			x = y;
			y = temp;
		} 
		if (x > z) {
			int temp1 = x;
			x = z;
			z = temp1;
		}
		if (y > z) {
			int temp2 = y;
			y = z;
			z = temp2;
		}
		System.out.println(x);
		System.out.println(y);
		System.out.println(z);
	}
	
//三个数
	@Test
	public void tets9() {
		System.out.println("输入三个数");
		Scanner scanner = new Scanner(System.in);
		System.out.println("输入第一个数");
		int x = scanner.nextInt();
		System.out.println("输入第二个数");
		int y = scanner.nextInt();
		System.out.println("输入第三个数");
		int z = scanner.nextInt();
		int temp;
		int temp1;
		int temp2;
		if (x > y) {
			temp = x;
			x = y;
			y  = temp;
		}
		if (x > z) {
			temp1 = x;
			x = z;
			z = temp1;
		}
		if (y > z) {
			temp2 = y;
			y = z;
			z = temp2;
		}
		System.out.println(x);
		System.out.println(y);
		System.out.println(z);
	}
	
	
}

